<template>
  <div class="app-container">
    <el-table
      :data="List"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
    >
      <el-table-column
        prop="tableName"
        label="表名"
      />
      <el-table-column
        prop="engine"
        label="引擎"
      />
      <el-table-column
        prop="tableComment"
        label="描述"
      />
      <el-table-column
        prop="tableCollation"
        label="表字符集"
      />
      <el-table-column
        prop="createTime"
        label="创建时间"
      />
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="handleGen(scope.row)">生成代码</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
import { getList, gen } from '@/api/gen'

export default {

  data() {
    return {
      parentId: '',
      List: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleGen(val) {
      this.$prompt('请输入代码对象名开头大写的字母', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        gen({ table: val.tableName, name: value }).then(res => {
          if (res.code === 200) {
            this.$notify({
              title: 'Success',
              dangerouslyUseHTMLString: true,
              message: `生成成功`,
              type: 'success'
            })
          } else {
            this.$notify({
              title: 'Error',
              dangerouslyUseHTMLString: true,
              message: `生成失败`,
              type: 'error'
            })
          }
        })
      }).catch(() => {
      })
    },
    async getList() {
      const res = await getList()
      this.List = res.data
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  .roles-table {
    margin-top: 30px;
  }

  .permission-tree {
    margin-bottom: 30px;
  }
}
</style>
